#!/bin/sh
#
# mmm_agent    This shell script takes care of starting and stopping
#              the mmm agent daemon.
#
# chkconfig: - 64 36
# description:	MMM Agent.
# processname: mmmd_agent
# config: /opt/mmm/mmm_agent.conf
# pidfile: /opt/mmm/var/mmmd_agent.pid

# Paths
MMMD_BASE="/opt/mmm"
MMMD_AGENT_BIN="${MMMD_BASE}/mmmd_agent"
MMMD_AGENT_PIDFILE="${MMMD_BASE}/var/mmmd_agent.pid"

#-----------------------------------------------------------------------
# See how we were called.
case "$1" in
  start)
	# Start daemon.
	echo -n "Starting MMM Agent daemon: "
	$MMMD_AGENT_BIN
	RETVAL=$?
	echo "Ok"
	;;

  stop)
	# Stop daemon.
	echo -n "Shutting down MMM Agent daemon: "
	kill `cat $MMMD_AGENT_PIDFILE`
	RETVAL=$?
	echo "Ok"
	;;

  restart|reload)
	$0 stop
	echo -n "Waiting 10 sec before restart...";
	sleep 10
	echo "Ok"
	$0 start
	;;

  *)
	echo "Usage: $0 {start|stop|restart}"
	RETVAL=1
	;;
esac

exit $RETVAL
